<?php
$section = 'testimonial';
$titre = _LB_TESTIMONIAL_MANAGEMENT;
$smarty->assign("titre", $titre);

//get object ID
$id = Request::getIntNumber('id');
$act = Request::getIntNumber('act');

//get back link
$backlink = Session::getBackLink($section,"list/?");

$testiminial = new Testimonial();
if($id)
{
	if(!$testiminial->get($id))
		redirect($backlink);
}

//if action = UPDATE or CREATE
if ($act == ACT_VALID_EDIT)
{
	$testiminial->NAME = trim(Request::get('NAME'));
	$testiminial->EMAIL = trim(Request::get('EMAIL'));
    $testiminial->COMMENT = trim(Request::get('COMMENT'));
    $testiminial->POS = trim(Request::get('POS'));
    $testiminial->STATUS = Request::getIntNumber('STATUS');
	
	if ($testiminial->validateInput())
	{
		$testiminial->save();

		redirect($backlink);
	}

}
//create cfer
$cfer = new Cfer(array(
	_LB_ACCUEIL => Utils::getHomeLink(),
	_LB_TESTIMONIAL_MANAGEMENT => $backlink,
	($id == 0? _LB_ADD_PRESS : _LB_EDIT_PRESS) => Utils::getCurrentLink() ));

//if validate is false, display form again
$smarty->assign('cfer', $cfer);
$smarty->assign('testimonial', $testiminial);
$smarty->assign('backlink', $backlink);
$smarty->display('testimonial_form.html');